#!/usr/bin/python

width = 16                      # 16 means 16x16

col_middle = width
pps_num = width/2+1                      # num of pps
cols_num = width*2
cols = ['']*cols_num

# for the low half of cols
for c in range(0, col_middle+2, 2):
    start_y = 0
    end_y = c/2
    start_x = c
    for i in range(start_y, end_y+1):
        cols[c] += "pp[%d][%d] + " % (i, start_x)
        cols[c+1] += "pp[%d][%d] + " % (i, start_x+1)
        start_x -= 2
    cols[c] = cols[c][:-3]            # strip the last '+'
    cols[c+1] = cols[c+1][:-3]

# the col_middle+1 calced above is not correct, clear it
cols[col_middle+1] = ''

# for the high half of cols
for c in range(col_middle+1, cols_num-3+2, 2):
    start_y = (c-col_middle-1)/2+1
    end_y = pps_num-1
    start_x = 15
    for i in range(start_y, end_y+1):
        cols[c] += "pp[%d][%d] + " % (i, start_x)
        cols[c+1] += "pp[%d][%d] + " % (i, start_x+1)
        start_x -= 2
    cols[c] = cols[c][:-3]
    cols[c+1] = cols[c+1][:-3]

# for the MSB col
cols[cols_num-1] = "pp[%d][%d]" % (pps_num-1, width-1)

# add the sign compensation bits
for c in range(0, col_middle, 2):
    cols[c] += " + S[%d]" % (c/2)

for c in range(col_middle+3, cols_num-1+2, 2):
    cols[c] = "E[%d] + %s" % ((c-col_middle-3)/2+1, cols[c])
    if c+1 < cols_num:
        cols[c+1] = "1 + " + cols[c+1]
# the special compensation for PP0
cols[col_middle+1] = "{~E[0]} + " + cols[col_middle+1] # add {} to void default bit expand ??
cols[col_middle+2] = "{~E[0]} + " + cols[col_middle+2]
cols[col_middle+3] = "E[0] + " + cols[col_middle+3]

# for i,v in enumerate(cols):
#     print "cols[%d] = %s" % (i, v)




print "logic [3:0] cols[31:0];\n"
for i,v in enumerate(cols):
    # print "assign cols[%d] = %s;" % (i, v)
    print "cols[%d] = %s;" % (i, v)




